// Growth-rate calculator
// ExtendedRational is a holder for non-negative rational numbers p/q,
// and their extensions of the form p/q+.
// By definition, a/b < p/q+ if a/b <= p/q, and
//                a/b > p/q+ if a/b > p/q.
// Using this notion, we can always say that exponents of a
// subword should be _less_ than a given number beta.
// If we want to allow exponents not greater than p/q, we can use beta=p/q+.

#ifndef GRATE_UTIL_EXT_RATIONAL_H
#define GRATE_UTIL_EXT_RATIONAL_H

#include <string>

#include "common.h"

namespace growth_rate {

struct ExtendedRational {
  ExtendedRational();
  explicit ExtendedRational(uint64_t x);
  ExtendedRational(uint64_t num, uint64_t denum, bool plus);

  ExtendedRational multiply(const ExtendedRational& other) const;
  // Returns negative number, if first number is less than second,
  // zero if they are equal, or positive, if the first number is larger.
  int64_t compare(const ExtendedRational& other) const;
  uint64_t int_value() const;

  // Output number in a human-readable format.
  std::string dump() const;

  // ExtendedRational is immutable.
  const uint64_t num;
  const uint64_t denum;
  const bool plus;  // true if number has the form num/denum+.
};

}  // namespace growth_rate

#endif  // GRATE_UTIL_EXT_RATIONAL_H
